<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        .container {
            width: 600px;
            margin: 0 auto;
        }
        h1 {
            text-align: center;
            padding-bottom: 20px;
        }
        p {
            text-align: center;
            font-size: 16px;
            color: gainsboro;
        }
        .row {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 40px;
        }
        .row span {
            width: 200px;
        }
        .row input {
            width: 200px;
            height: 30px;
        }
        .row .submit {
            width: 400px;
            background-color: orange;
            color: white;
            border: 0;
        }
        .row .submit:active {
            background-color: greenyellow;
        }
    </style>
</head>
<body>
    <h1>表白墙</h1>
    <p>输入后点击提交，会将信息显示在表格中</p>
    <div class="container">
        <div class="row">
            <span>谁</span>
            <input type="text" class="from">
        </div>
        <div class="row">        
            <span>对谁</span>
            <input type="text" class="to"> 
        </div>
       <div class="row">
           <span>说什么</span>        
           <input type="text" class="message">
        </div>
        <div class="row">
            <input type="button" value="提交" class="submit">
        </div>
    </div>
    <script>
        let container = document.querySelector('.container')
        let input = document.querySelectorAll('input');
        let submit = document.querySelector('.submit');
        
        submit.onclick = function(){
            let from = input[0].value;
            let to = input[1].value;
            let message = input[2].value;

            if(from == '' || to == '' || message == ''){
                return;
            }

            let div = document.createElement('div');
            div.className = 'row';
            div.innerHTML = from + '对' + to + '说' + message;

            container.appendChild(div);

            for (let word of input) {
                word.value = '';
            }
        }
    </script>
</body>
</html>